package com.gamatechno.adapter;

import java.security.KeyStore.Builder;
import java.util.ArrayList;
import java.util.HashMap;

import com.gamatechno.solodestination.Tab;
import com.gamatechno.solodestination.R;
import com.gamatechno.solodestination.model.Komentar;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.style.ClickableSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;

public class LazyAdapterTab extends BaseAdapter {

	private Activity activity;
	private ArrayList<Komentar> data;
	private static LayoutInflater inflater = null;
	public ImageLoader imageLoader; 
	ImageLoader imgloader;

	public LazyAdapterTab(Activity a, ArrayList<Komentar> d) {
		activity = a;
		imageLoader= new ImageLoader(activity);
		data = d;
		inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

	}

	public int getCount() {
		return data.size();
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		View vi = convertView;
		if (convertView == null)
			vi = inflater.inflate(R.layout.tab_item, null);
		ImageView tab_img = (ImageView) vi.findViewById(R.id.tab_img);
		TextView tab_nama = (TextView) vi.findViewById(R.id.tab_nama);
		TextView tab_tgl = (TextView) vi.findViewById(R.id.tab_tgl);
		TextView tab_text = (TextView) vi.findViewById(R.id.tab_text);
		RatingBar tab_rating = (RatingBar) vi.findViewById(R.id.tab_rating);
		HashMap <String, String> d = new HashMap <String, String>();
        Komentar kom = data.get(position);
		tab_nama.setText(kom.getName());
		tab_tgl.setText(kom.getComment());
		tab_text.setText(kom.getUser_comment());
		float aa=0;
		try {
			aa=Float.parseFloat(kom.getRating());
		} catch (Exception e) {
			// TODO: handle exception
		}
		tab_rating.setRating(aa);
//		imageLoader.DisplayImage(d.get(Tab.KEY_IMG), tab_img);
		//tab_img.setImageResource(Integer.parseInt(d.get(Tab.KEY_IMG)));
		String url="";
		imageLoader.DisplayImage(url, tab_img);
		return vi;
	}
}
